package com.niit.lcy.spectagsrate;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: Chase
 * @Date: 2024/12/10
 */

public class SpecTagsRateMapper extends Mapper<LongWritable, Text, Text, Text> {
    private Text outk = new Text();
    private Text outv = new Text();

    /**
     * map阶段的核心业务逻辑（按行读取，获小区名和标签信息，组合成kv，然后输出）
     *
     * @param key
     * @param value
     * @param context
     * @throws IOException
     * @throws InterruptedException
     */
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        if (key.get() == 0) // 跳过标题行
            return;

        String lineData = value.toString();
        String[] datas = lineData.split("\t");
        if (datas.length >= 12) {
            outk.set(datas[1]);
            outv.set(datas[12]);
            context.write(outk, outv);
        }
    }
}
